package Tests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import Model.Game;
import Model.Player;

/**
 * 
 * @author Emily Curtin
 *
 */
public class GameTest {
	private Game game;
	private Player[] players;
	private String red = "RED";
	private String blue = "BLUE";
	private String yellow = "YELLOW";
	private String green = "GREEN";
	private String notAColor = "ELEPHANT";
	
	@Before
	/**
	 * Initialize the game
	 */
	public void initTestElements() {
		game = new Game();
		players = game.getPlayers();
		
	}
	
	/**
	 * Test to see if the game functions OK when all colors are different
	 */
	@Test
	public void duplicateColorsTestAllDifferent() {
		setColorsAllDifferent1();
		assertFalse(game.duplicateColors());
	}
	/**
	 * Test to see if the game fails when two players have the same color, Red
	 */
	@Test
	public void duplicateColorsTestTwoSame(){
		setColorsTwoRed();
		assertTrue(game.duplicateColors());
	}
	
	/**
	 * Test to see if the game fails when three players have the same color
	 */
	@Test
	public void duplicateColorsTestThreeSame(){
		setColorsThreeRed();
		assertTrue(game.duplicateColors());
	}
	
	/**
	 * test to see if the game fails when 4 players have the same color
	 */
	@Test
	public void duplicateColorsTestAllSame(){
		setColorsFourRed();
		assertTrue(game.duplicateColors());
	}
	
	/**
	 * test to see if the game fails when one player has an invalid color
	 */
	@Test
	public void duplicateColorsNotAColor(){
		setPlayer0ToNotAColor();
		assertFalse(game.duplicateColors());
	}
	
	/**
	 * this occurs after every test
	 */
	@After
	public void cleanUp() {
		players = null;
		game = null;
	}
	
	/**
	 * function to set all colors as different
	 */
	public void setColorsAllDifferent1() {
		players[0].setColor(red);
		players[1].setColor(blue);
		players[2].setColor(green);
		players[3].setColor(yellow);
	}
	
	/**
	 * function to set player0's color to an invalid value
	 */
	public void setPlayer0ToNotAColor() {
		players[0].setColor(notAColor);
		players[1].setColor(blue);
		players[2].setColor(green);
		players[3].setColor(yellow);
	}
	
	/**
	 * function to set 2 player colors to red
	 */
	public void setColorsTwoRed() {
		players[0].setColor(red);
		players[1].setColor(red);
		players[2].setColor(green);
		players[3].setColor(yellow);
	}
	
	/**
	 * function to set three player colors to red
	 */
	public void setColorsThreeRed() {
		players[0].setColor(red);
		players[1].setColor(red);
		players[2].setColor(red);
		players[3].setColor(yellow);
	}
	
	/**
	 * function to set four player colors to red
	 */
	public void setColorsFourRed() {
		players[0].setColor(red);
		players[1].setColor(red);
		players[2].setColor(red);
		players[3].setColor(red);
	}
	

}
//public boolean duplicateColors()
//{
//	for (int i=0; i<players.length; i++)
//	{
//		for (int j=i+1; j<players.length; j++)
//		{
//
//			if ( players[i].getColor() == players[j].getColor() )
//			{
//				return true;
//			}
//		}
//	}
//
//	return false; //otherwise no duplicates
//
//}